var express = require('express');
var Msdb = require("../../../db/Msdb.js");
var router = express.Router();   //可使用 express.Router 类创建模块化、可挂载的路由句柄
const jwt = require('jsonwebtoken');
var Excel = require('exceljs');
var multer = require('multer');
var UUID = require('uuid');
var request = require("request");
const { getxl_util, getnowdate, saveczlog_util, res_util, checkbysql, addformfield, getnowdate_djh, setformfield,
   insert_table, update_table_wstr, update_table_byid, resutdata_to_formdata, resutdata_to_formdata_arr, save_qlczslog_util,
   usequery } = require('./server_util.js')

const log = require('../../../logger.js');
const db = require('../../../db/Redisdb.js');
const { getSmsStatusReport } = require('./ship_note.js');
var logger = require('../../../logger.js').logger;

//查询发送记录
router.post('/fsjl', async function (req, res) {
   let rtdata2 = await getSmsStatusReport()
   let result = JSON.parse(rtdata2)
   console.log(result,"result");
   //判断rtdata2是否是数组
   if(Array.isArray(result)){
    result.forEach(async element => {
       await usequery(`update shipSRM_fsjl set fssj = getdate(),fszt = '${element.status=='0'?'发送成功':'发送失败'}' where uid = '${element.uid}'
         and phone='${element.phone}'`)
    });
   }
   var rtdata = await usequery(`select * from shipSRM_fsjl order by create_time desc`)
   res_util(res, rtdata, true, "查询成功")
})
module.exports = router; 